package com.bw.message.adapter

import android.graphics.Color
import android.util.Log
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.bw.common.utils.MyTimeUtils
import com.bw.message.model.MessageEntity
import com.bw.message.R
import com.bw.message.model.MessageState
import com.bw.message.model.MessageType
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

class MessageAdapter : BaseQuickAdapter<MessageEntity, BaseViewHolder>(R.layout.message_item) {
    override fun convert(holder: BaseViewHolder, item: MessageEntity) {
        holder.setText(R.id.tv_type, item.messageType)
        holder.setText(R.id.tv_content, item.messageContent)
        holder.setText(R.id.tv_state, item.messageStatus)
        holder.setText(R.id.tv_time, MyTimeUtils.allTimeToDay(item.sendTime))

        val img_message = holder.getView<ImageView>(R.id.img_message)
        val tv_state = holder.getView<TextView>(R.id.tv_state)


        //根据不同类型
        when (item.messageType) {
            MessageType.SYSTEM.value -> {
                Glide.with(img_message).load(R.drawable.message_03).into(img_message)
            }
            MessageType.SERVICE.value -> {
                Glide.with(img_message).load(R.drawable.message_06).into(img_message)
            }
            MessageType.MENAGE.value -> {
                Glide.with(img_message).load(R.drawable.message_08).into(img_message)
            }
        }

        when (item.messageStatus) {
            MessageState.READ.value -> {
                tv_state.setBackgroundResource(R.drawable.bg_state_blue)
            }
            MessageState.PROCESS.value -> {
                tv_state.setBackgroundResource(R.drawable.bg_state_green)
            }
            MessageState.EXPIRED.value -> {
                tv_state.setBackgroundResource(R.drawable.bg_state_gray)
            }
        }

    }


}